package org.example.web;

import org.example.base.BaseResp;
import org.example.service.UserService;
import org.example.utils.ElasticSearchUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author huangy
 * @description
 * @since 2023/2/10 16:58
 **/
@RestController
@RequestMapping("test")
public class TestController {

    @Resource
    private ElasticSearchUtils elasticSearchUtils;

    @Resource
    private UserService userService;

    /*
     * @description 新增数据
     * @author huangy
     * @since 2023/2/10 18:21
     * @return org.example.base.BaseResp<?>
     **/
    @PostMapping("/add")
    public BaseResp<?> add() {
        userService.addUser();
        return BaseResp.success();
    }

    /*
     * @description 通过id获取用户信息
     * @author huangy
     * @since 2023/2/15 15:07
     * @param id
     * @return org.example.base.BaseResp<?>
     **/
    @GetMapping("getUser")
    public BaseResp<?> getUser(long id) {
        return BaseResp.success(userService.getUserById(id));
    }

    /*
     * @description 获取数据
     * @author huangy
     * @since 2023/2/15 14:47
     * @return org.example.base.BaseResp<?>
     **/
    @GetMapping("getUsers")
    public BaseResp<?> getUsers(String name) {
        return BaseResp.success(userService.getUsers(name));
    }

    /*
     * @description 获取所有用户
     * @author huangy
     * @since 2023/2/15 15:07
     * @return org.example.base.BaseResp<?>
     **/
    @GetMapping("getAllUsers")
    public BaseResp<?> getAllUsers() {
        return BaseResp.success(userService.getAllUses());
    }

    @GetMapping("update")
    public BaseResp<?> update(long id) {
        userService.updateById(id);
        return BaseResp.success();
    }

}
